/**
 * Created by no1 on 2015/6/26.
 */
'use strict';

let F = require('../common/function');
let _ = require('underscore');

// 定义命令分类

let actionGroupArray = ['shop',
  'ware',
  'district',
  'category',
  'vendor',
  'permission',
  'role',
  'order',
  'user',
  'appConfig',
  'article',
  'authority',
  'wiki',
  'coupon',
  'counter',
  'payway',
  'payway',
  'checkout'
];

//// 测试环境API
//var C = require('../config/index.js');
//if (C.env === 'development' || C.env === 'test') {
//    actionGroupArray.push('article');
//}


function* o2o_service_API(Env) {
  let I = Env['I'];
  let action = I['action'];
  let actionGroup = I['actionGroup'];

  if (_.isObject(o2o_service_API[actionGroup]) && _.isFunction(o2o_service_API[actionGroup][action])) {
    console.log('Group:' + actionGroup + '  Action:' + action);

    return yield o2o_service_API[actionGroup][action](Env);
  } else {
    return F.returnMsg(400, 'ERROR', 3, {});
  }
}

// 读取数组中的文件
actionGroupArray.map(file => {
  let tmp = require('../common/' + file);
  o2o_service_API[file] = tmp.api;
});

module.exports = o2o_service_API;